Skip to content

fix: paragraphs styles detection - #124

Merged
IvanIhnatsiuk merged 1 commit into
developmentfrom
fix/paragarph-styles-detection
Jul 15, 2026
Merged

fix: paragraphs styles detection#124
IvanIhnatsiuk merged 1 commit into
developmentfrom
fix/paragarph-styles-detection

Conversation

@IvanIhnatsiuk

Copy link
Copy Markdown
Collaborator

Summary

This pull request refactors and improves the handling of paragraph and list styles within the Android EnrichedText editor. The changes focus on making the application and removal of styles more robust, consistent, and maintainable, especially when dealing with zero-width spaces and multi-paragraph selections. The code now uses replacement-based updates for styling, improves span boundary safety, and enhances style state detection logic.

Refactoring and Consistency Improvements

  • Refactored the application of list and paragraph styles to use dedicated replacement builders (buildStyledListReplacement and buildStyledParagraphReplacement), ensuring more consistent handling of zero-width spaces and multi-paragraph selections.
  • Improved span removal logic to safely handle boundaries and avoid errors, and to ensure zero-width spaces are properly removed or inserted as needed.

Style State Detection and Emission

  • Reworked the logic for detecting and emitting the current style state, especially for paragraph and list styles, by introducing new helper methods like getCoveredParagraphStyleStart and enhancing alignment handling.

Span Application and Alignment

  • Updated span application to use applyParagraphSpan instead of direct setSpan calls for list styles, improving the reliability of span application over paragraphs.
  • Modified alignment application to apply alignment spans per paragraph within a list, ensuring more granular and accurate alignment styling.

Code Quality and Safety

  • Added safety checks for span boundaries (e.g., using coerceAtMost, coerceAtLeast, coerceIn) to prevent out-of-bounds errors.

Minor Improvements

  • Updated imports and replaced usage of EnrichedParagraphSpan with EnrichedSpan for better type safety and future extensibility.
  • Minor fixes to ensure that zero-width spaces are inserted or removed in a transaction-safe manner, reducing the risk of inconsistent text state.

Test Plan

First scenario

  1. Open the editor app
  2. Apply lisst styles
  3. Type some text
  4. Apply alignment

Second scenario

  1. Type two paragraphs of text
  2. Apply any header styles
  3. Select these two paragraphs
  4. Observe that heading style is enabled in the toolbar
  • Steps to reproduce the bug (if this is a bug fix)
  • Steps to verify the new feature
  • Expected vs actual results
  • Any special conditions or edge cases to test

Screenshots / Videos

First scenario

Screen.Recording.2026-07-15.at.17.55.54.mov

Second scenario

Screen.Recording.2026-07-15.at.18.00.14.mov

Compatibility

OS Implemented
iOS ✅❌
Android ✅❌

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Android EnrichedText paragraph/list style handling to make style application/removal and toolbar state detection more robust across multi-paragraph selections and zero-width spaces (ZWS).

Changes:

  • Added a Spannable.getParagraphRanges() helper to better handle paragraph iteration, including trailing-newline cases.
  • Refactored list/paragraph style application to build replacements (buildStyledListReplacement, buildStyledParagraphReplacement) and apply spans per-paragraph.
  • Reworked selection style-state detection (including alignment) to require full paragraph coverage and consistent alignment across selected paragraphs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
android/src/main/java/com/swmansion/enriched/utils/Utils.kt Adds getParagraphRanges() to generate paragraph ranges including empty trailing paragraphs.
android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt Updates paragraph/list style detection logic (including alignment consistency across paragraphs).
android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt Refactors paragraph style application/removal and applies alignment to list paragraphs individually.
android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt Refactors list styling to replacement-based updates and uses applyParagraphSpan for list spans.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IvanIhnatsiuk
IvanIhnatsiuk merged commit bf9f4f8 into development Jul 15, 2026
1 check passed
@IvanIhnatsiuk
IvanIhnatsiuk deleted the fix/paragarph-styles-detection branch July 15, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants